package com.itheima.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.domain.City;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.w3c.dom.ls.LSInput;

import java.util.List;

@Controller
@RequestMapping("/city")
@ResponseBody
public class CityController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findAll")
    public List<City> findAll(Model model) throws JsonProcessingException {
        List<City> list = userService.findAll();
//        String json = new ObjectMapper().writeValueAsString(list);
        return list;
    }

    public City findById(String id) {
        int cid = Integer.parseInt(id);
        City city = userService.findByCId(cid);
        return city;
    }
}
